<template>
  <div class="goods-list">
    <my-header myheader="商品列表"></my-header>
    <ul
      v-infinite-scroll="loadMore"
      infinite-scroll-disabled="loading"
      infinite-scroll-distance="10"
      infinite-scroll-immediate-check="false"
    >
      <router-link class="goods-li" :to="`/goods_list/${itme.id}/goods_detail`" tag="li" v-for="(itme,index) in Datalist" :key="index">
        <div class="goods-container">
          <img :src="itme.img_url" alt="">
          <h4>{{itme.title}}</h4>
          <div class="goods-info">
            <div class="price-info">
              <span class="price-new">￥{{itme.sell_price}}</span>
              <span class="price-old">￥{{itme.market_price}}</span>
            </div>
            <div class="sell-info">
              <span class="sell-status">热卖中</span>
              <span class="sell-leftcount">剩余{{itme.stock_quantity}}件</span>
            </div>
          </div>
        </div>
      </router-link>
    </ul>
  </div>
</template>

<script>
import MyHeader from '@/components/myheader'
import {getgoods} from '@/api/goodsApi'
export default {
  data () {
    return {
      pageindex: 1,
      Datalist: [],
      loading: false
    }
  },

  components: {
    MyHeader
  },

  computed: {},

  mounted () {
    this.getDatalist()
  },

  methods: {
    getDatalist () {
      getgoods(this.pageindex)
        .then(res => {
          // console.log(res)
          if (res.status === 0) {
            this.Datalist = res.message
          }
        })
    },
    loadMore () {
      this.loading = true
      this.pageindex += 1
      getgoods(this.pageindex)
        .then(res => {
        // console.log(res)
          if (res.status === 0) {
            this.Datalist = this.Datalist.concat(res.message)
            this.loading = false
          }
        })
    }
  }
}

</script>
<style lang='scss' scoped>
.goods-list {
  background-color: #f4f4f4;
  ul {
    display: flex;
    flex-wrap: wrap;
    font-size: 10px;
  }
  h4 {
    font-size: 12px;
    font-weight: bold;
    height: 32px;
    // 多行文本超出省略号
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
  }
  .goods-li {
    width: 50%;
    box-sizing: border-box;
    padding-top: 5px;
    display: flex;
    justify-content: column;
    .goods-container {
      width: 100%;
      background-color: #fff;
      padding: 5px;
      display: flex;
      flex-direction: column;
      justify-content: center;
    }
    .price-info {
      display: flex;
      justify-content: space-between;
      .price-new {
        color: red;
      }
      .price-old {
        text-decoration: line-through;
      }
    }
    .sell-info {
      display: flex;
      justify-content: space-between;
    }
  }

  .goods-li:nth-child(2n+1) {
    padding-right: 5px;
  }
  .goods-li:nth-child(2n) {
    padding-left: 5px;
  }
}
</style>
